import config from '../config/main';
import mongoose from 'mongoose';

function middleware(_app) {
    const app = _app;
    const log = app.log.getLogger('[dbm]');

    // connect to db
    mongoose.connect(config.mongo.uri, config.mongo.options);
    const conn = mongoose.connection;


    conn.on('error', () => {
        log.error('connect error');
    });
    conn.once('open', () => {
        log.info('connect open');
    });

    return function* dispatch(next) {
        yield next;
    };
}

export default middleware;
